package com.gxuwz.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSourceFactory;


public class DBUtil {
    private static final String CONFIG = "dbcp.properties";
    
    private static DataSource dataSource;
 
    static {
        Properties dbProperties = new Properties();
        try {
            dbProperties.load(DBUtil.class.getClassLoader()
                    .getResourceAsStream(CONFIG));
            dataSource = BasicDataSourceFactory.createDataSource(dbProperties);
        } catch (Exception e) {
        	e.printStackTrace();
        }
    }
    
    public static final Connection getConnection() {
        Connection conn = null;
        try {
            conn = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}
